package com.shixun.entity;

import org.hibernate.annotations.GenericGenerator;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by haiyan on 2016/12/11.
 */
@Entity
@Table(name = "file")
@Component
@Scope("prototype")
public class FileEntity{

    private static final long serialVersionUID = 1L;
    private String id;
    private UserEntity UserEntity;
    private String fname;
    private String fmain;
    private Timestamp ftime;
    private String fphotoName;
    private String fphoneAddress;
    private String fnumber;
    private String fdianzan;
    private String type;
    private String state;
    private Timestamp createtime;
    private String more1;
    private String more2;


    @Override
    public String toString() {
        return "FileEntity{" +
                "id='" + id + '\'' +
                ", UserEntity='" + UserEntity + '\'' +
                ", fname='" + fname + '\'' +
                ", fmain='" + fmain + '\'' +
                ", ftime=" + ftime +
                ", fphotoName='" + fphotoName + '\'' +
                ", fphoneAddress='" + fphoneAddress + '\'' +
                ", fnumber='" + fnumber + '\'' +
                ", fdianzan='" + fdianzan + '\'' +
                ", type='" + type + '\'' +
                ", state='" + state + '\'' +
                ", createtime=" + createtime +
                ", more1='" + more1 + '\'' +
                ", more2='" + more2 + '\'' +
                '}';
    }

    public FileEntity() {
    }
    /**
     * toXml return Map
     */
    public Map<String, Object> toMap() {
        Map<String, Object> voMap = new HashMap<>();
        voMap.put("id", id);
        if (UserEntity != null) {
            voMap.put("UserEntity", UserEntity.toMap());
        }
        voMap.put("fname", fname);
        voMap.put("fmain", fmain);
        voMap.put("ftime", TimeMaker.toDateTimeStr(ftime));
        voMap.put("fphotoName", fphotoName);
        voMap.put("fphoneAddress", fphoneAddress);
        voMap.put("fnumber", fnumber);
        voMap.put("fdianzan", fdianzan);
        voMap.put("type", type);
        voMap.put("state", state);
        voMap.put("createtime", TimeMaker.toDateTimeStr(createtime));
        voMap.put("more1", more1);
        voMap.put("more2", more2);
        return voMap;
    }

    public FileEntity(String id,UserEntity UserEntity, String fname, String fmain, Timestamp ftime, String fphotoName, String fphoneAddress, String fnumber, String fdianzan, String type, String state, Timestamp createtime, String more1, String more2) {
        this.id = id;
        this.UserEntity = UserEntity;
        this.fname = fname;
        this.fmain = fmain;
        this.ftime = ftime;
        this.fphotoName = fphotoName;
        this.fphoneAddress = fphoneAddress;
        this.fnumber = fnumber;
        this.fdianzan = fdianzan;
        this.type = type;
        this.state = state;
        this.createtime = createtime;
        this.more1 = more1;
        this.more2 = more2;
    }

    @GenericGenerator(name = "generator", strategy = "uuid")
    @Id
    @GeneratedValue(generator = "generator")
    @Column(name = "Id" ,unique = true, nullable = false)
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fuser")
    public UserEntity getUserEntity() {
        return this.UserEntity;
    }

    public FileEntity setUserEntity(UserEntity UserEntity) {
        this.UserEntity = UserEntity;
        return this;
    }
    @Basic
    @Column(name = "fname")
    public String getFname() {
        return fname;
    }

    public void setFname(String fname) {
        this.fname = fname;
    }

    @Basic
    @Column(name = "fmain")
    public String getFmain() {
        return fmain;
    }

    public void setFmain(String fmain) {
        this.fmain = fmain;
    }

    @Basic
    @Column(name = "ftime")
    public Timestamp getFtime() {
        return ftime;
    } public void setFtime(Timestamp ftime) {
        this.ftime = ftime;
    }
    @Basic
    @Column(name = "fphotoName")
    public String getFphotoName() {
        return fphotoName;
    }

    public void setFphotoName(String fphotoName) {
        this.fphotoName = fphotoName;
    }

    @Basic
    @Column(name = "fphoneAddress")
    public String getFphoneAddress() {
        return fphoneAddress;
    }

    public void setFphoneAddress(String fphoneAddress) {
        this.fphoneAddress = fphoneAddress;
    }

    @Basic
    @Column(name = "fnumber")
    public String getFnumber() {
        return fnumber;
    }

    public void setFnumber(String fnumber) {
        this.fnumber = fnumber;
    }

    @Basic
    @Column(name = "fdianzan")
    public String getFdianzan() {
        return fdianzan;
    }

    public void setFdianzan(String fdianzan) {
        this.fdianzan = fdianzan;
    }

    @Basic
    @Column(name = "type")
    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    @Basic
    @Column(name = "state")
    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    @Basic
    @Column(name = "createtime")
    public Timestamp getCreatetime() {
        return createtime;
    } public void setCreatetime(Timestamp createtime) {
        this.createtime = createtime;
    }
    @Basic
    @Column(name = "more1")
    public String getMore1() {
        return more1;
    }

    public void setMore1(String more1) {
        this.more1 = more1;
    }

    @Basic
    @Column(name = "more2")
    public String getMore2() {
        return more2;
    }

    public void setMore2(String more2) {
        this.more2 = more2;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        FileEntity that = (FileEntity) o;

        if (id != null ? !id.equals(that.id) : that.id != null) return false;
        if (UserEntity != null ? !UserEntity.equals(that.UserEntity) : that.UserEntity != null) return false;
        if (fname != null ? !fname.equals(that.fname) : that.fname != null) return false;
        if (fmain != null ? !fmain.equals(that.fmain) : that.fmain != null) return false;
        if (ftime != null ? !ftime.equals(that.ftime) : that.ftime != null) return false;
        if (fphotoName != null ? !fphotoName.equals(that.fphotoName) : that.fphotoName != null) return false;
        if (fphoneAddress != null ? !fphoneAddress.equals(that.fphoneAddress) : that.fphoneAddress != null)
            return false;
        if (fnumber != null ? !fnumber.equals(that.fnumber) : that.fnumber != null) return false;
        if (fdianzan != null ? !fdianzan.equals(that.fdianzan) : that.fdianzan != null) return false;
        if (type != null ? !type.equals(that.type) : that.type != null) return false;
        if (state != null ? !state.equals(that.state) : that.state != null) return false;
        if (createtime != null ? !createtime.equals(that.createtime) : that.createtime != null) return false;
        if (more1 != null ? !more1.equals(that.more1) : that.more1 != null) return false;
        if (more2 != null ? !more2.equals(that.more2) : that.more2 != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (UserEntity != null ? UserEntity.hashCode() : 0);
        result = 31 * result + (fname != null ? fname.hashCode() : 0);
        result = 31 * result + (fmain != null ? fmain.hashCode() : 0);
        result = 31 * result + (ftime != null ? ftime.hashCode() : 0);
        result = 31 * result + (fphotoName != null ? fphotoName.hashCode() : 0);
        result = 31 * result + (fphoneAddress != null ? fphoneAddress.hashCode() : 0);
        result = 31 * result + (fnumber != null ? fnumber.hashCode() : 0);
        result = 31 * result + (fdianzan != null ? fdianzan.hashCode() : 0);
        result = 31 * result + (type != null ? type.hashCode() : 0);
        result = 31 * result + (state != null ? state.hashCode() : 0);
        result = 31 * result + (createtime != null ? createtime.hashCode() : 0);
        result = 31 * result + (more1 != null ? more1.hashCode() : 0);
        result = 31 * result + (more2 != null ? more2.hashCode() : 0);
        return result;
    }
}
